package com.hzw.code.pageState

import android.content.Context
import android.view.View
import android.view.ViewStub
import android.widget.FrameLayout
import androidx.annotation.LayoutRes
import com.hzw.code.R
import com.scwang.smartrefresh.layout.listener.OnRefreshListener

/**
 *
 * @Author:         HuaZhongWei
 * @CreateDate:     2020/4/16 17:43
 *
 * @Description:    容器，自带下拉刷新。主要用于空界面，错误界面
 *
 */
class PageViewStub(val context: Context, @LayoutRes val layoutResId: Int) {

    var isEnableRefresh = false

    var imageViewId = 0
    var imageResId = 0

    var tipsViewId = 0
    var tipsText: String? = null

    var retryViewId = 0
    var retryText: String? = null

    var onRetryListener: OnRetryListener? = null
    var onRefreshListener: OnRefreshListener? = null

    val viewStub: ViewStub

    init {
        viewStub = ViewStub(context, R.layout.layout_page_view_stub)
    }

    fun inflate(): View {
        val view = viewStub.inflate()
        val container= view.findViewById<FrameLayout>(R.id.pageContainer)
        val realView = View.inflate(context, layoutResId, null)
        container.removeAllViews()
        container.addView(realView)
        return view
    }
}